<template>
	<view class="" style="padding-bottom: 150rpx;">
		<view class="margin_top ffffff mainpadding radius" v-for="item in list.data" :key="item.id">
			<view class="flexbetween">
				<view class="">
					<view class="ershib xiaohei fonweight">{{item.name}}</view>
					<view class="ershib xiaohui margin_top1">{{item.type.name}} {{item.type1.name}}</view>
					<view class="ershib xiaohui margin_top1">{{item.carno}}</view>
				</view>
				<image class="tupian" :src="item.image_text" mode=""></image>
			</view>
			<view class="flexbetween margin_top">
				<view class="bjbtn flexcenter" @click="tzbjxx(item.id)">编辑</view>
				<view class="shancbtn flexcenter" @click="delitem(item.id)">删除</view>
			</view>
		</view>
		<view class="gudingdb mainpadding" @click="tianjia()">
			<view class="bigbtn">添加</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			delitem(id) {
				httpRequest.modal('提示', '是否确认删除当前数据', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/user/delUserCar', 'GET', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/userCarIndex', 'GET', {
					page: page || 1,
					limit: _this.limit,
					index_rec: 1,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转编辑信息
			tzbjxx(id) {
				uni.navigateTo({
					url: '/pages_wode/cheliangxxbj?id='+id
				})
			},
			tianjia() {
				uni.navigateTo({
					url: '/pages_wode/cheliangxxbj'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shancbtn {
		width: 337rpx;
		height: 75rpx;
		background: #FF9341;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.bjbtn {
		width: 337rpx;
		height: 75rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border: 2rpx solid #FF9341;
	}

	.tupian {
		width: 222rpx;
		height: 137rpx;
		border-radius: 17rpx 17rpx 17rpx 17rpx;
	}
</style>